package com.example.bookmanager;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.xuyang.other.Flags;
import com.xuyang.other.ProgressDialog;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class ResetPwActivity extends Activity {
	private ImageView mImgFinish;
	private Button mBtnSubmit;
	private EditText mEditUName;
	
	private RequestQueue mQueue;
	private AlertDialog mDialog;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_reset_pw);
		init();
		mImgFinish.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		mBtnSubmit.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				mDialog.show();
				String url=Flags.RESET_PW.replace("UNAME", mEditUName.getText().toString());
				StringRequest request=new StringRequest(url, new Response.Listener<String>() {
					@Override
					public void onResponse(String str) {
						mDialog.dismiss();
						if (str.equals("ok")) {
							Toast.makeText(getBaseContext(), "操作成功", 0).show();
						}else {
							Toast.makeText(getBaseContext(), "操作失败", 0).show();
						}
					}
				}, new Response.ErrorListener() {
					@Override
					public void onErrorResponse(VolleyError arg0) {
						mDialog.dismiss();
						Toast.makeText(getBaseContext(), "请检查网络连接", 0).show();
					}
				});
				mQueue.add(request);
			}
		});
	}
	private void init() {
		mImgFinish=(ImageView) findViewById(R.id.img_resetpw_finish);
		mEditUName=(EditText) findViewById(R.id.edit_resetpw_uname);
		mBtnSubmit=(Button) findViewById(R.id.btn_resetpw_submit);
		mQueue=Volley.newRequestQueue(this);
		mDialog=new ProgressDialog(this).getDialog();
		mDialog.dismiss();
	}
	
}
